<?php if (!defined('THINK_PATH')) exit(); /*a:1:{s:64:"E:\static\tp5\public/../application/index\view\socket\index.html";i:1515480452;}*/ ?>
<!DOCTYPE html>
<html>
<head>
	<title></title>
</head>
<body>
hello; <button class="login"> login</button>
<button class="socket">sokcet</button>
<script src="https://cdn.bootcss.com/jquery/3.0.0-rc1/jquery.min.js"></script>
<script type="text/javascript">

  $(function(){
     var testsid  = '';
     $('.login').click(function(){
         $.post('http://www.query.com/admin',{},function(e){
             var result =   e.data;
             testsid        = result.sid;
         });
     });
     $('.socket').click(function(event) {
        ws = new WebSocket("ws://192.168.0.164:8683");
        ws.onmessage = function(e){
            // json数据转换成js对象
            var data = eval("("+e.data+")");
            var type = data.type || '';
            switch(type){
                // Events.php中返回的init类型的消息，将client_id发给后台进行uid绑定
                case 'init':
                    // 利用jquery发起ajax请求，将client_id发给后端进行uid绑定
                    $.get('http://www.query.com/admin/socket_gate', {client_id: data.client_id,sid:testsid}, function(data){
                        console.log(data);
                    });
                   break;
                // 当mvc框架调用GatewayClient发消息时直接alert出来
                default :
                    console.debug(e.data);
            }
         };
     });
  })

	/*ws = new WebSocket("ws://192.168.0.164:8683");
	
	

	
	// 服务端主动推送消息时会触发这里的onmessage
	ws.onmessage = function(e){
    // json数据转换成js对象
    var data = eval("("+e.data+")");
    var type = data.type || '';
    switch(type){
        // Events.php中返回的init类型的消息，将client_id发给后台进行uid绑定
        case 'init':
            // 利用jquery发起ajax请求，将client_id发给后端进行uid绑定
            $.get('http://www.query.com/admin/socket_gate', {id: 1}, function(data){
            	console.log(data);
            });
           break;
        // 当mvc框架调用GatewayClient发消息时直接alert出来
        default :
            console.debug(e.data);
    }
 };*/
</script>
</body>
</html>